/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import main.Main;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import main.Controller;
import model.Ninja;
/**
 *
 * @author Peter
 */
public class NinjaController implements AnalogListener {
    
    private final Ninja ninja;
    private final float speed;
    private view.NinjaView ninjaView;
    
    public NinjaController(Ninja ninja, Main app, float speed){
        this.ninja = ninja;
        this.speed = speed;
        ninjaView = new view.NinjaView(app);
        ninja.addListener(ninjaView);
        ninja.init();
        
    }
    
    public void onAnalog(String name, float value, float tpf) {
        if (name.equals(Controller.PLAYER_TURN_LEFT)) {
          this.ninja.turnLeft(value*this.speed);
        } else if (name.equals(Controller.PLAYER_TURN_RIGHT)) {
          this.ninja.turnRight(value*this.speed);
        } else if (name.equals(Controller.PLAYER_WALK_FORWARD)) {
            float cycle = ninjaView.getAnimCycle("Walk");
            if (cycle>.5){
                this.ninja.walkForward(value*5f);
            } else {
                this.ninja.walkForward(value*8f);
            }
        } else if (name.equals(Controller.PLAYER_BACKFLIP)) {
          this.ninja.backFlip();
        }
//        if (name.equals("Right")) {
//          Vector3f v = player.getLocalTranslation();
//          player.setLocalTranslation(v.x + value*speed, v.y, v.z);
//        }
//        if (name.equals("Left")) {
//          Vector3f v = player.getLocalTranslation();
//          player.setLocalTranslation(v.x - value*speed, v.y, v.z);
//        }
    }

}
